<?php
// 用户的消费记录控制器

if (!isset($_SESSION['user_level']) || $_SESSION['user_level'] < 90 ||
    !isset($_SESSION['user_admin']) || $_SESSION['user_admin'] != 1
) {
    echo '无管理员权限';
    goto page_end;
}

require_once("{$CfgPara->root}/class/pay.class.php");
$myPay = new CPay($CfgPara->database);

// 用户购买记录的详细页面 当前仅用户本领编辑有此页面
if (isset($InputData['consume_id'])) {
    $consumeContentList = $myPay->consume_content_list($InputData['consume_id']);
    if (is_string($consumeContentList)) {
        echo $consumeContentList;
        goto page_end;
    }
    require("{$viewRoot}user_buy_record_content{$viewEx}");
    goto page_end;
}

// 用户购买记录的首页
if (!isset ($InputData['page_change'])) // 如果没有切换页，则全部加载
{
    // 标题搜索栏
    $searchTittle = '购买记录';
    $tittleText = '购买记录';
    require("{$viewRoot}tittle_back_bar{$viewEx}");

    // 消费数据统计
    $consumeTotal = $myPay->consume_total_count();
    $consumeLastMonth = $myPay->consume_lastmonth_count();
    $consumeToday = $myPay->consume_today_count();

    // 页数索引默认为1
    $page_index = 1;
} else {
    // 消费数据统计
    $consumeTotal = $myPay->consume_total_count();
    $page_index = $InputData['page_change'];
}

// 消费记录 分页
if ($consumeTotal->TotalCount > 0) {
    $consumeList = $myPay->consume_list($page_index, $CfgPara->pagesize);
    if (is_string($consumeList)) {
        echo $consumeList;
        goto page_end;
    }
    //连接分页类 在列表最后加入分页栏
    require_once("{$CfgPara->root}/class/paginate.class.php");
    $myPaginate = new paginate_c();
    $myPaginate->change_func = 'consume_recorde_page_change([x])';
    $paginateMsg = $myPaginate->paginate($page_index, ceil($consumeTotal->TotalCount / $CfgPara->pagesize));
}


if (!isset($InputData['page_change']))
    require("{$viewRoot}user_buy_record{$viewEx}");
else
    require("{$viewRoot}user_buy_record_page{$viewEx}");

page_end:;